import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author nhsoft.lul
 */
public class Application {

    static String URL = "jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf-8&serverTimezone=UTC";
    static String USER = "root";
    static String PASSWORD = "123456";

    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(URL, USER, PASSWORD);

            String sql = "drop table if exists student";
            statement = conn.prepareStatement(sql);
            statement.execute();

            sql = "create table student (id int primary key,name varchar(20))";
            statement = conn.prepareStatement(sql);
            statement.execute();


            conn.setAutoCommit(false);
            sql = "insert into student(id,name) values(?, ?)";
            statement = conn.prepareStatement(sql);
            for (int i = 0; i < 100; i++) {
                statement.setInt(1, (i + 1));
                statement.setString(2, "lul" + i);
                statement.addBatch();
            }
            statement.executeBatch();
            conn.commit();
            conn.setAutoCommit(true);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }

        }
    }

}
